use common::util::run_command;
use std::path::{Path, PathBuf};

const PROJECT_FOLDER_NAME: &str = "temp_project";
const GIT_TEMPLATE_URL: &str = "https://gitee.com/hanshu_alan/template1.git";
pub fn init_project(dir: &Path) -> Result<PathBuf, Box<dyn std::error::Error>> {
    let project_path = dir.join(PROJECT_FOLDER_NAME);

    if project_path.exists() && project_path.is_dir() {
        return Ok(project_path);
    }

    run_command(
        dir,
        "git",
        &["clone", GIT_TEMPLATE_URL, project_path.to_str().unwrap()],
    )?;

    Ok(project_path)
}
